package com.juli.aimanager.system.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.juli.aimanager.common.BuildTree;
import com.juli.aimanager.common.Tree;
import com.juli.aimanager.dao.BaseDao;
import com.juli.aimanager.system.dto.MenuDO;
import com.juli.aimanager.system.service.MenuService;
/**
 * 菜单实现类
 * @author 小帅丶
 * @类名称  MenuServiceImpl
 * @remark 
 * @date  2017-9-18
 */
@Service("menuService")
public class MenuServiceImpl implements MenuService{
	
	@Resource(name="baseDao")
	private BaseDao baseDao;

	public Tree<MenuDO> getSysMenuTree(Long id) throws Exception {
		Map map=new HashMap();
		String sql = "select distinct m.menu_id , parent_id, name, url, perms, `type`, icon, order_num, gmt_create, gmt_modified from sys_menu m left join sys_role_menu rm on m.menu_id = rm.menu_id left join sys_user_role ur on rm.role_id = ur.role_id where ur.user_id = "+id+" and m.type in(0,1)";
		List<Tree<MenuDO>> trees = new ArrayList<Tree<MenuDO>>();
		List<MenuDO> menuDOs = this.baseDao.findAllObject(sql,MenuDO.class);
		for (MenuDO sysMenuDO : menuDOs) {
			Tree<MenuDO> tree = new Tree<MenuDO>();
			tree.setId(sysMenuDO.getMenuId().toString());
			tree.setParentId(sysMenuDO.getParentId().toString());
			tree.setText(sysMenuDO.getName());
			Map<String, Object> attributes = new HashMap();
			attributes.put("url", sysMenuDO.getUrl());
			attributes.put("icon", sysMenuDO.getIcon());
			tree.setAttributes(attributes);
			trees.add(tree);
		}
		Tree<MenuDO> tree = BuildTree.build(trees);
		return tree;
	}

	public Tree<MenuDO> getTree() {
		// TODO Auto-generated method stub
		return null;
	}

	public Tree<MenuDO> getTree(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	public List<MenuDO> list() {
		// TODO Auto-generated method stub
		return null;
	}

	public int remove(Long id) {
		// TODO Auto-generated method stub
		return 0;
	}

	public int save(MenuDO menu) {
		// TODO Auto-generated method stub
		return 0;
	}

	public int update(MenuDO menu) {
		// TODO Auto-generated method stub
		return 0;
	}

	public MenuDO get(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	public Set<String> listPerms(Long userId) {
		// TODO Auto-generated method stub
		return null;
	}

}
